var api = require("api");
var util=require("../utils/util");

// 城市选择
function get_all_city_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getAllCityList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 首页分类
function get_home_classify_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.homeClassifyList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// banner广告
function get_home_banner_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.bannerList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 首页课程导航
function get_home_nav(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.homeNavCour,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 课程分类
function get_cate_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.cateList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 课程列表
function get_cour_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.courList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 课程详情
function get_cour_detail(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.courDetail,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 课程评价列表
function get_cour_comment(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.courComment,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 课程收藏
function call_cour(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.callCour,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 课程分享
function cour_share(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.courShare,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 课程浏览
function cour_browse(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.courBrowse,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        // util.show_success_toast(res)
      },
      fail: function () {
        reject();
        // util.show_fail_toast()
      },
    })
  })
}
// 课程套餐详情(支付)
function get_cour_meal_detail(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getCourMeal,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 机构列表
function get_mech_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.mechList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 机构详情
function get_mech_detail(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.mechDetail,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 机构课程列表
function get_mech_cour_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getMechCourList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 机构收藏
function call_mech(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.callMech,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 机构取消收藏
function cancel_call_mech(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.cancelCallMech,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 机构浏览
function mech_browse(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.mechBrowse,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        // util.show_success_toast(res)
      },
      fail: function () {
        reject();
        // util.show_fail_toast()
      },
    })
  })
}
// 课程优惠券列表
function get_cour_pref_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.courPrefList,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 机构优惠券列表
function get_mech_pref_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.mechPrefList,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 领取优惠券
function get_pref(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getPref,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 获取可用优惠券
function get_user_pref(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getUserPref,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 生成订单
function create_order(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.createOrder,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        // util.show_success_toast(res)
      },
      fail: function (res) {
        reject(res);
        util.show_fail_toast()
      },
    })
  })
}
// 支付订单
function pay_order(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.payOrder,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 支付0元订单
function payment_order(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.paymentOrder,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 购买成功后送礼品券
function send_pref_after(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.sendPrefAfter,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 热门搜索
function get_hot_search() {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getHotSearch,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 最近搜索
function get_near_nearch(token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getNearSearch,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 添加最近搜索
function add_search(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.addSearch,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 删除搜索
function del_search(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.delSearch,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 分类分页课程列表
function get_class_cour_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.classCourList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 获取名师列表
function get_teach_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getTeachList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 获取名师详情
function get_teach_info(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getTeachInfo,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 关注老师
function add_focus_teacher(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.addFocusTeacher,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 取消关注
function cancel_focus_teacher(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.cancelFocusTeacher,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}

// 获取名师课程
function get_teach_cour(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getTeachCour,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 获取名师评论
function get_teach_comment(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getTeachComment,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}

module.exports={
  get_all_city_list,
  get_home_classify_list,
  get_home_banner_list,
  get_home_nav,
  get_cate_list,
  get_cour_list,
  get_cour_detail,
  get_cour_comment,
  call_cour,
  cour_share,
  cour_browse,
  get_cour_meal_detail,
  get_mech_list,
  get_mech_detail,
  get_mech_cour_list,
  call_mech,
  cancel_call_mech,
  mech_browse,
  get_cour_pref_list,
  get_mech_pref_list,
  get_pref,
  get_user_pref,
  create_order,
  pay_order,
  payment_order,
  send_pref_after,
  get_hot_search,
  get_near_nearch,
  add_search,
  del_search,
  get_class_cour_list,
  get_teach_list,
  get_teach_info,
  add_focus_teacher,
  cancel_focus_teacher,
  get_teach_cour,
  get_teach_comment
}